package lee.vioson.ebook.viewmodels

import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.stateIn
import lee.vioson.composecommon.base.mvi.BaseViewModel
import lee.vioson.composecommon.base.mvi.Reducer
import lee.vioson.composecommon.base.mvi.UiEvent
import lee.vioson.composecommon.base.mvi.UiState
import lee.vioson.remotedata.bean.PurchaseHistory

/**
 *Author:viosonlee
 *Date:2023/6/12
 *DESCRIPTION:
 */
class PurchaseHistoryViewModel :
    BaseViewModel<PurchaseHistoryViewModel.State, PurchaseHistoryViewModel.Event>() {

    private val reducer = SubReducer(State())

    override val state: StateFlow<State>
        get() = reducer.state

    override fun sendEvent(event: Event) {
        reducer.sendEvent(event)
    }

    val list = flow {
        emit(
            listOf(
                PurchaseHistory(
                    time = 1686535246,
                    type = "Monthly subscription",
                    amount = 59.9
                ),
                PurchaseHistory(
                    time = 1686535246,
                    type = "Monthly subscription",
                    amount = 59.9
                ),
                PurchaseHistory(
                    time = 1686535246,
                    type = "Monthly subscription",
                    amount = 59.9
                ), PurchaseHistory(
                    time = 1686535246,
                    type = "Monthly subscription",
                    amount = 59.9
                )
            )
        )
    }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), listOf())

    private class SubReducer(initialState: State) :
        Reducer<State, Event>(initialState) {
        override fun reduce(oldState: State, event: Event) {

        }
    }


    sealed class Event : UiEvent {

    }

    class State : UiState {

    }
}

